package com.local.service.impl;

import com.base.dao.DAO;
import com.base.util.PageData;
import com.local.service.CommonManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by lee on 2016/6/24.
 */
@Service("commonService")
public class CommonServiceImpl implements CommonManager {

    @Resource(name = "daoSupport")
    private DAO daoSupport;

    public void insertUpdCommon(PageData pd, String path) {
        try {
            daoSupport.save(path,pd);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void deleteCommon(PageData pd, String path) {
        try {
            daoSupport.delete(path,pd);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public int getInfoCommonCount(PageData pd, String path) {
        PageData countPd = new PageData();
        try {
            countPd = (PageData) daoSupport.findForObject(path,pd);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Integer.valueOf(countPd.get("CHUGUOCOUNT").toString());
    }

    public List<PageData> getInfoCommon(PageData pd, String path) {

        List<PageData> info = new ArrayList<PageData>();
        try {
            info = (List<PageData>) daoSupport.findForList(path,pd);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return info;
    }

    public PageData getInfoCommonByID(PageData pd, String path) {
        PageData info = new PageData();
        try {
            info = (PageData) daoSupport.findForObject(path,pd);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return info;
    }
}
